import config from "../../../config/config";
import * as request from '../../../utils/request';

export function getDocumentList(params) {
    return request.get(`${config.api.rag.getDocumentList}`, params, false);
}

export function deleteDocument(params) {
    return request.post(`${config.api.rag.deleteDocument}`, params, false);
}

export function previewDocument(params) {
    return request.get(`${config.api.rag.previewDocument}`, params, false);
}

export function uploadDocument(params) {
    request.upload(`${config.api.rag.uploadDocument}`, params);
}

export function addDocumentWebsite(params) {
    return request.post(`${config.api.rag.addDocumentWebsite}`, params, false);
}

export function downloadDocument(params) {
    return request.downlaod(`${config.api.rag.downloadDocument}`, params, "blob").then(res => {
        let event = document.createEvent("MouseEvents");
        let a = document.createElement("a");
        a.href = window.URL.createObjectURL(res);
        a.download = params.documentName;
        event.initEvent("click", true, true);
        a.dispatchEvent(event);
    });
}
